﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            var name = this.textBox1.Text;
            var pwd = this.textBox2.Text;
            var tryPwd = this.textBox3.Text;
            bool hasName = !string.IsNullOrEmpty(name);
            bool hasPwd = !string.IsNullOrEmpty(pwd);
            bool Equal = pwd == tryPwd;
            var sql = string.Format("select*from Users where Username='{0}'and Password='{1}'",name,pwd);
            DbHelper db = new DbHelper();
            var res = DbHelper.GetDataTable(sql);
            if (res.Rows.Count > 0)
            {
                MessageBox.Show("该用户已经注册");
            }
            else if (hasName && hasPwd && Equal)
            {
                var insertString = string.Format("insert into Users(Username,Password) values('{0}','{1}')", name, pwd);
                var dt = DbHelper.AddOrUpdateOrDelete(insertString);
                MessageBox.Show("注册成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("注册失败");
            }
           


        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
